import subprocess
from multiprocessing import Process, Queue 
import os
import time
CWD_DIR = os.path.split(os.path.abspath(__file__) )[0]

def ping():
	flag="1"
	while True:
		fnull = open(os.devnull, 'w')
		return1 = subprocess.call('ping 61.135.169.125 -c 3', shell = True, stdout = fnull, stderr = fnull)
		if return1:
			print('Internet not connected!')
			cmd =  ('lxterminal kill $(pgrep python3)')
			pp= subprocess.Popen(cmd , shell=True , stdout=subprocess.PIPE , cwd=CWD_DIR)
			flag ="1"

		else:
			print('Internet connected!')
			if flag =="1":
				try:
					flag ="0"
					cmd = ('lxterminal -e python3 sock.py')
					ppp = subprocess.Popen(cmd , shell=True , stdout=subprocess.PIPE , cwd=CWD_DIR)
				except Exception as e:
					print(e)

		fnull.close()
def main():
	time.sleep(5)
	ping()
if __name__ == "__main__":
	main()

